<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>

		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/form.css"/>
	</head>
	<body>
	<div class="main">
		<h3>用户注册</h3>
		<div class="login-form">
			<p>
				<input placeholder="请输入用户名" class="username input">
			</p>
			<p>
				<input id="#phone"placeholder="请输入手机号码" class="userPhone input">
			</p>
			<p>
				<input placeholder="请输入密码" type="password" class="password input">
			</p>
			<p>
				<input placeholder="请确认密码" type="password" class="password input">
			</p>
			<p>
				<input type='button' value="点击注册" class="btn" onclick="reg()">
			</p>
			<p>
				<a class="login" href="login.html"><input type='button' value="已有账号点击登录" class="btn"></a>
			</p>
		</div>
	</div>

	</body>
	<script src="qrcode/jquery-3.5.1.min.js"></script>
	<script src="/layer/layer.js"></script>
	<script>
		let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
		function reg(){

			let phone = $.trim($('#phone').val());


			//1.    获取用户输入的用户名 帐号 密码
			let username = $("input:eq(0)").val();
			let userPhone = $("input:eq(1)").val();
			let password1 = $("input:eq(2)").val();
			let password2 = $("input:eq(3)").val();

			if(password1 == password2){
				//2.    将用户的账号密码, 通过ajax发送到服务器
				let  windowId=layer.load();
				$.post("/wx/reg.do",
						{"username":username,
						"userPhone":userPhone,
						 "password1":password1
						},function(data){
					layer.close(windowId);
					if(data.status == 0){
						layer.msg(data.result)
						window.location.href="login.html";
					}else{
						layer.msg(data.result);
					}
				},"JSON");
				return false;

				//3.    接收服务器回复的内容
			}else{
				layer.msg("两次密码输入不一致",function(){});
			}


		}
	</script>
</html>
